SET(CMAKE_CXX_STANDARD 11)

include_directories(${CMAKE_SOURCE_DIR}/libonvif/generated)
add_compile_options("-std=c++11")
if (SELF_OPENSSL)
    find_library(OpenSSL_cryptro_PATH NAMES libeay libeay32 libcrypto libcrypto32 eay crypto PATHS /usr/local/lean/openssl-3.0.16 PATH_SUFFIXES "lib64" NO_DEFAULT_PATH)
    find_library(OpenSSL_ssl_PATH NAMES ssleay ssleay32 libssl libssl32 eay ssl  PATHS /usr/local/lean/openssl-3.0.16 PATH_SUFFIXES "lib64" NO_DEFAULT_PATH)
    find_path(OpenSSL_include_DIR NAMES openssl/ssl.h  PATHS /usr/local/lean/openssl-3.0.16 PATH_SUFFIXES "include" NO_DEFAULT_PATH)
else ()
    find_library(OpenSSL_cryptro_PATH NAMES libeay libeay32 libcrypto libcrypto32 eay crypto PATH_SUFFIXES "lib")
    find_library(OpenSSL_ssl_PATH NAMES ssleay ssleay32 libssl libssl32 eay ssl PATH_SUFFIXES "lib")
    find_path(OpenSSL_include_DIR NAMES openssl/ssl.h  PATH_SUFFIXES "include")
endif ()

set(HAS_OPENSSL OFF)
if(OpenSSL_include_DIR AND OpenSSL_cryptro_PATH AND OpenSSL_ssl_PATH)
    set(HAS_OPENSSL ON)
    message(STATUS "OpenSSL found: ${OpenSSL_include_DIR} ${OpenSSL_cryptro_PATH} ${OpenSSL_ssl_PATH}")
endif()
if(HAS_OPENSSL)
    include_directories("${OpenSSL_include_DIR}")
    message(STATUS "SSL/TLS enabled")
    add_definitions(-DWITH_OPENSSL)
    #add_definitions(-DWITH_DOM)
else()
    message(STATUS "SSL/TLS disabled because of missing OpenSSL library")
endif()

set(src_files
        generated/soapC.cpp
        generated/soapwsddProxy.cpp
        gsoap/duration.c
        gsoap/stdsoap2.cpp
        gsoap/dom.cpp
        gsoap/wsaapi.c
        gsoap/struct_timeval.c
)

if(HAS_OPENSSL)
    set(src_files ${src_files} gsoap/smdevp.c gsoap/httpda.c gsoap/mecevp.c gsoap/wsseapi.cpp)
else()
    set(src_files ${src_files} gsoap/wsseapi-lite.c)
endif()

# private header
#set(private_header_files
#        gsoap/stlvector.h
#)

# public header
set(public_header_files
        generated/soapStub.h
        generated/soapwsddProxy.h
        generated/soapH.h
        gsoap/stdsoap2.h
        gsoap/wsaapi.h
        gsoap/struct_timeval.h
)

if(HAS_OPENSSL)
    set(public_header_files ${public_header_files} gsoap/smdevp.h gsoap/threads.h gsoap/mecevp.h gsoap/wsseapi.h)
else()
    set(public_header_files ${public_header_files} gsoap/wsseapi-lite.h)
endif()

set_source_files_properties(${src_files} PROPERTIES LANGUAGE CXX)

add_library(dsonvif ${src_files} ${public_header_files})# ${private_header_files}
target_include_directories(dsonvif
        PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}> $<INSTALL_INTERFACE:include>
        PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/gsoap> $<INSTALL_INTERFACE:include>
        PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/generated> $<INSTALL_INTERFACE:include>
        PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>)
target_compile_definitions(dsonvif PUBLIC WITH_OPENSSL WITH_DOM WITH_NONAMESPACES)
if(HAS_OPENSSL)
    message(STATUS "SSL/TLS enabled: ${OpenSSL_cryptro_PATH} ${OpenSSL_ssl_PATH}")
    target_link_libraries(dsonvif "${OpenSSL_ssl_PATH}" "${OpenSSL_cryptro_PATH}")
endif()



